package cn.edu.scau.cmi.chenjia.client;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.control.TextField;
import javafx.scene.control.TextArea;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import cn.edu.scau.cmi.chenjia.singleton.Marshal;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Paint;

public class MutipletonClient extends Application {
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) {
		primaryStage.setTitle("Mutipleton");

		TextField tf1 = new TextField();
		tf1.setLayoutX(257);
		tf1.setLayoutY(100);
		tf1.setPrefWidth(300);
		tf1.setPrefHeight(30);

		TextArea tf2 = new TextArea();
		tf2.setLayoutX(0);
		tf2.setLayoutY(150);
		tf2.setPrefWidth(656);
		tf2.setPrefHeight(401);

		Button button = new Button("Establish");
		button.setLayoutX(558);
		button.setLayoutY(100);
		button.setPrefWidth(100);
		button.setPrefHeight(30);

		Label lb = new Label("Please enter the Marshal's name:");
		lb.setLayoutX(10);
		lb.setLayoutY(100);
		lb.setPrefWidth(250);
		lb.setPrefHeight(30);

		Group group = new Group();
		group.getChildren().add(button);
		group.getChildren().add(tf1);
		group.getChildren().add(tf2);
		group.getChildren().add(lb);

		button.setOnMouseClicked(e -> {
			String name = tf1.getText();
			Marshal.addInstance(name);
			if (Marshal.complete()) {
				String temp = "the input is enough";
				tf2.appendText(temp + '\n');
			} else
				tf2.appendText(name + '\n');

		});

		Scene scene = new Scene(group);

		primaryStage.setScene(scene);
		primaryStage.setHeight(600);
		primaryStage.setWidth(675);
		primaryStage.show();
	}

}